Converting Arguments to C Scalars

The routines described in this section convert the value of their IDL_VARIABLE argument to the C scalar type indicated by their name. IDL_MEMINTScalar() and IDL_FILEINTScalar() exist for processing memory and file sizes without the need to know their actual types, as discussed in “IDL_MEMINT and IDL_FILEINT Types”. The converted value is returned as the function value. The functions are defined as:

IDL_LONG IDL_LongScalar(IDL_VPTR p)

IDL_ULONG IDL_ULongScalar(IDL_VPTR v)

IDL_LONG64 IDL_Long64Scalar(IDL_VPTR v)

IDL_ULONG64 IDL_ULong64Scalar(IDL_VPTR v)

double IDL_DoubleScalar(IDL_VPTR p)

IDL_MEMINT IDL_MEMINTScalar(IDL_VPTR p)

IDL_FILEINT IDL_FILEINTScalar(IDL_VPTR p)

If these functions are unable to perform the conversion (e.g., the argument is a file variable, an array, etc.), they issue a descriptive error and jump back to the interpreter. By using these functions, you avoid having to do any of the type checking described in Checking Arguments.

For example, the following IDL system function (named PRINT_LONG) prints the value of its first argument, converted to an IDL_LONG 32-bit integer:

IDL_VPTR print_long(int argc, IDL_VPTR argv[], char *argk)

{

printf("%d\n", IDL_LongScalar(argv[0]));

}

Executing it as:

PRINT_LONG, 23D

gives the output:

23

as expected, while the statement:

PRINT_LONG, FINDGEN(10)

causes the error:

% PRINT_LONG: Expression must be a scalar in this context:

<FLOAT Array(10)>

% Execution halted at $MAIN$ .

because it is not possible to convert an array (the result of FINDGEN) to a scalar.